<template>
    <div class="app-container home">
        <el-row :gutter="40" class="panel-group">
            <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
                    <div class="card-panel-icon-wrapper icon-people">
                        <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
                    </div>
                    <div class="card-panel-description">
                        <div class="card-panel-text">出院总数</div>
                        <count-to :start-val="0" :end-val="countAll" :duration="3000" class="card-panel-num"/>
                    </div>
                </div>
            </el-col>
            <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('messages')">
                    <div class="card-panel-icon-wrapper icon-message">
                        <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
                    </div>
                    <div class="card-panel-description">
                        <div class="card-panel-text">报销总数</div>
                        <count-to :start-val="0" :end-val="reimburseAll" :duration="3000" class="card-panel-num"/>
                    </div>
                </div>
            </el-col>
            <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('purchases')">
                    <div class="card-panel-icon-wrapper icon-money">
                        <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
                    </div>
                    <div class="card-panel-description">
                        <div class="card-panel-text">今日出院人数</div>
                        <count-to :start-val="0" :end-val="todayCount" :duration="3200" class="card-panel-num"/>
                    </div>
                </div>
            </el-col>
            <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
                <div class="card-panel" @click="handleSetLineChartData('shoppings')">
                    <div class="card-panel-icon-wrapper icon-shoppingCard">
                        <svg-icon icon-class="peoples" class-name="card-panel-icon"/>
                    </div>
                    <div class="card-panel-description">
                        <div class="card-panel-text">今日报销人数</div>
                        <count-to :start-val="0" :end-val="reimburseCount" :duration="3600" class="card-panel-num"/>
                    </div>
                </div>
            </el-col>
        </el-row>
        <h3 style="margin-left: 3%;margin-top: 3%">近期报销人数</h3>
        <div style="margin-top: 3%">
            <div class="echart" id="mychart" :style="myChartStyle"></div>
        </div>
    </div>
</template>

<script setup name="Index">
import {CountTo} from 'vue3-count-to';
import {info, reloadPieIndex} from '@/api/system/notice';
import {getCurrentInstance, onMounted, reactive, ref, toRefs} from 'vue'
import * as echarts from 'echarts';

const {proxy} = getCurrentInstance();
const countAll = ref(0);
const reimburseAll = ref(0);
const todayCount = ref(0);
const reimburseCount = ref(0);


const xData = ref(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]);
const yData = ref([23, 24, 18, 25, 27, 28, 25]);
const taskDate = ref([10, 11, 9, 17, 14, 13, 14]);
const myChartStyle = ref({float: "left", width: "100%", height: "400px"});

function handleSetLineChartData(type) {
    proxy.$emit('handleSetLineChartData', type)
}

const data = reactive({
    barChartData: {
        chartData: [],
        xAxisData: []
    }
});

const {barChartData} = toRefs(data);

/** 查询页面显示的数据 */
function getList() {
    info().then(response => {
        countAll.value = response.data.countAll
        reimburseAll.value = response.data.reimburseAll
        todayCount.value = response.data.todayCount
        reimburseCount.value = response.data.reimburseCount
    })
}

/** 查询柱状图、饼图显示的数据 */
function loadPieData() {
    reloadPieIndex().then(resp => {
        let xZData = []
        let yZData = []
        let taskZDate = []
        for (const respKey in resp.data) {
            // console.log(JSON.stringify(resp.data[respKey]))
            xZData.unshift(resp.data[respKey].disDept)
            yZData.unshift(resp.data[respKey].disWard)
            taskZDate.unshift(resp.data[respKey].patientId)
        }
        xData.value = xZData
        yData.value = yZData
        taskDate.value = taskZDate
        // 多列柱状图
        const mulColumnZZTData = {
            xAxis: {
                data: xData.value
            },
            // 图例
            legend: {
                data: ["出院人数", "报销人数"],
                top: "0%"
            },
            yAxis: {},
            series: [
                {
                    type: "bar", //形状为柱状图
                    data: yData.value,
                    name: "出院人数", // legend属性
                    label: {
                        // 柱状图上方文本标签，默认展示数值信息
                        show: true,
                        position: "top"
                    }
                },
                {
                    type: "bar", //形状为柱状图
                    data: taskDate.value,
                    name: "报销人数", // legend属性
                    label: {
                        // 柱状图上方文本标签，默认展示数值信息
                        show: true,
                        position: "top"
                    }
                }
            ]
        };
        const myChart = echarts.init(document.getElementById("mychart"));
        myChart.setOption(mulColumnZZTData);
        //随着屏幕大小调节图表
        window.addEventListener("resize", () => {
            myChart.resize();
        });
    })
}


onMounted(async () => {
    setTimeout(() => {
        loadPieData()
    }, 1000)
})


getList();
const version = ref('3.8.5')
</script>

<style scoped lang="scss">
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shoppingCard {
        background: #34bfa3
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shoppingCard {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}
</style>

